﻿using MESMian.Context;
using Microsoft.EntityFrameworkCore.Migrations.Internal;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace MESMian.Forms.ProductionSpec
{
    public partial class ProductionSpecDetail : Form
    {
        int primaryId = 0;
        public ProductionSpecDetail(int primaryId)
        {
            InitializeComponent();
            this.primaryId = primaryId;
            Load += ProductionSpecDetail_Load;
        }

        private void ProductionSpecDetail_Load(object? sender, EventArgs e)
        {
            using (var mtx = new MyContext())
            {
                var model = mtx.ProductSpecs.Find(primaryId);
                if (model != null)
                {
                    lblProductSpecsId.Text = model.ProductSpecId.ToString();
                    lblProductSpecsName.Text = model.ProductSpecName;
                    lblStatus.Text = model.Status == 0 ? "正常" : "禁用";
                    lblStatus.ForeColor = model.Status == 0 ? Color.Black : Color.Red;
                    var userModel1 = mtx.Users.Find(model.CreateUserId);
                    if (userModel1 != null)
                    {
                        lblCreateUserName.Text = userModel1.UserName;
                    }
                    lblCreateTime.Text = model.CreateTime.ToString("yyyy-MM-dd HH:mm");
                    if (model.LastUpdateUserId != null)
                    {
                        var userModel2 = mtx.Users.Find(model.LastUpdateUserId);
                        if (userModel2 != null)
                        {
                            lblLastUpdateUserName.Text = userModel2.UserName;
                        }
                    }
                    else
                    {
                        lblLastUpdateUserName.Text = "无";
                    }
                    if (model.LastUpdateTime != null)
                    {
                        lblLastUpdateTime.Text = ((DateTime)model.LastUpdateTime).ToString("yyyy-MM-dd HH:mm");
                    }
                    else
                    {
                        lblLastUpdateTime.Text = "无";
                    }
                }
            }
        }
    }
}
